﻿using BCCServer.Common.Common;
using BCCServer.Model.ModelsOut;
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Nancy.Json;
using System.Net;
using System.Text.Json;

namespace BCCServer.Web.Filter
{
    public class ManagerAuthorizeAttribute : Attribute, IAuthorizationFilter
    {
        public  void OnAuthorization(AuthorizationFilterContext  context)
        {
            
            var rs = TokenHelper.DecodeToken(context);

            if (rs== StatusCodes.Status100Continue)
            {
                
            }
            else if (rs== StatusCodes.Status403Forbidden)
            {
                ThrowException(context, StatusCodes.Status403Forbidden);
            }
            else
            {
                ThrowException(context, StatusCodes.Status401Unauthorized);
            }
        }

        private static void ThrowException(AuthorizationFilterContext context, int statusCodes)
        {
            context.Result = new JsonResult(new BaseOut { code = "true", content = statusCodes });
        }

    }
}
